#define _CRT_SECURE_NO_WARNINGS
#include"queue.h"
void QueueInitial(Queue* pq)
{
	assert(pq);
	pq->head = NULL;
	pq->tail = NULL;
}
void QueueDestroy(Queue* pq)
{
	assert(pq);
	QueueNode* current = pq->head, * next = NULL;
	while (current)
	{
		next = current->next;
		free(current);
		current = next;
	}
	pq->head = pq->tail = NULL;
}
void QueuePush(Queue* pq, QDataType x)
{
	assert(pq);
	QueueNode* newNode = (QueueNode*)malloc(sizeof(QueueNode));
	newNode->val = x;
	newNode->next = NULL;
	if (pq->head == NULL)
	{
		pq->head = pq->tail = newNode;
	}
	else
	{
		pq->tail->next = newNode;
		pq->tail = newNode;
	}
}
void QueuePop(Queue* pq)
{
	assert(pq);
	assert(pq->head);
	QueueNode* current = pq->head;
	pq->head = current->next;
	if (pq->tail == current)
		pq->tail = NULL;
	free(current);
}
QDataType QueueFront(Queue* pq)
{
	assert(pq);
	assert(pq->head);
	return pq->head->val;
}
QDataType QueueBack(Queue* pq)
{
	assert(pq);
	assert(pq->head);
	return pq->tail->val;
}
int QueueSize(Queue* pq)
{
	assert(pq);
	int count = 0;
	QueueNode* current = pq->head;
	while (current)
	{
		count++;
		current = current->next;
	}
	return count;
}
bool QueueEmpty(Queue* pq)
{
	assert(pq);
	return pq->head == NULL;
}